package com.michael.staticproxy.datasouce;

import javax.xml.bind.annotation.XmlType;
import javax.xml.transform.Source;

public class DynamicDataSourceEntity {

    private final static ThreadLocal<String> local = new ThreadLocal<>();

    private final static String DEFAULT_DATASOURCE = null;

    private DynamicDataSourceEntity(){}

    public static String getLocal(){
        return local.get();
    }

    public static void setLocal(String source){
        System.out.println("设置当前数据源为:"+source);
        local.set(source);
    }

    public static void setLocal(int year){
        String dbsource = "DB_"+year;
        System.out.println("设置当前数据源为："+dbsource);
        local.set(dbsource);
    }

    public static void restore(){
        System.out.println("恢复数据源为默认数据源:"+DEFAULT_DATASOURCE);
        local.set(DEFAULT_DATASOURCE);
    }
}
